/***********************************************************
  MOR.h
  Model Order Reduction Class
  SMART -- Symbolic Moment Analysis for Rapid Timing
  07-01-2008
  (c) Guoyong Shi;  SJTU
  09-11-2008
  Zhigang Hao; SJTU
 ***********************************************************/


#ifndef MOR_H
#define MOR_H

#include	<stdio.h>
#include	<stdlib.h>

#include	<iostream>
#include	<fstream>
#include <vector>

#include "RDD.h"
#include "RDDStruct.h"


// For queueing C_NODEs in BFS
struct Queue_Node {
  C_NODE		*nodeC;
  Queue_Node	*next;
};



class MOR
{
  public:
    MOR(int size_f, int size_r, RDD *rdd);
    ~MOR();

    void	Gram_Schmidt_RC();
    void	Gram_Schmidt_RLC();

    void Reduce_C_G_RC(C_NODE *ctree);
    void Reduce_C_G_RLC(C_NODE *ctree);

    void Print_V(FILE *file);
    void Print_Reduced_C_G(FILE *file);
#ifdef ORIG_MATRIX
    void Print_Orig_C_G(FILE *file);
#endif
  private:

    RDD		*MDD;			// RDD is a nickname for MDD.

    int		FullSize;			// (= n) size of full-order model
    int		ReducedSize;	// (= q) size of reduced-order model

    // Spaces for reduced-order matrices (in dense form).
    double	**C_hat;		// C_hat = V\T C V   (q x q)
    double	**G_hat;		// G_hat = V\T G V   (q x q)
    double	**VT;			// the transposed projection matrix (q x n)
#ifdef ORIG_MATRIX
    double  **G;   // original G matrix, n x n for RC, 2n x 2n for RLC
    double  *C;   // original C matrix diagonal
#endif
};


#endif

